"""
@author: wg
@file: 快速排序.py
@time: 2023/12/12 21:45
"""


# python实现快速排序

def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quick_sort(left) + middle + quick_sort(right)


# 示例
arr = [3, 6, 8, 10, 1, 2, 1]
print(quick_sort(arr))
